package app;

import core.MarkdownToHtml;
import core.SimpleMarkdownToHtml;
import io.FileService;

import java.nio.file.Path;

public class App {
    public static void main(String[] args) throws Exception {
        if (args.length < 2) {
            System.err.println("用法: java app.App <输入md路径> <输出html路径>");
            System.exit(1);
        }

        Path in = Path.of(args[0]);
        Path out = Path.of(args[1]);

        FileService fs = new FileService();
        String md = fs.read(in);

        MarkdownToHtml converter = new SimpleMarkdownToHtml();
        String body = converter.convert(md);

        String fullHtml = wrapHtml(body);
        fs.write(out, fullHtml);

        System.out.println("转换完成: " + out.toAbsolutePath());
    }

    private static String wrapHtml(String body) {
        return """
               <!doctype html>
               <html lang="zh-CN">
               <head>
                 <meta charset="utf-8" />
                 <meta name="viewport" content="width=device-width, initial-scale=1" />
                 <title>Markdown 转换结果</title>
                 <style>
                   body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif; line-height: 1.6; padding: 24px; max-width: 800px; margin: auto; }
                   h1, h2 { margin: 1em 0 .5em; }
                   p { margin: .6em 0; }
                   strong { font-weight: 700; }
                   em { font-style: italic; }
                 </style>
               </head>
               <body>
               """ + body + """
               </body>
               </html>
               """;
    }
}

